package org.vectrics.recruiter.struts.cv;

import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.jsp.JspException;

import org.vectrics.cv.Language;
import org.vectrics.cv.Level;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.struts.Request;
import org.vectrics.struts.VectricsActionData;
import org.vectrics.struts.VectricsStrutsAction;
import org.vectrics.user.Person;

public class ShowStudiesAction extends VectricsStrutsAction {

	private LanguageForm form;
	
	public LanguageForm getForm() {
		return form;
	}

	public void setForm(LanguageForm form) {
		this.form = form;
	}
	
	@Override
	protected String doExecute(VectricsActionData actionData)
			throws JspException {
		
		// Seteo el formulario 
		this.setForm((LanguageForm) actionData.getForm());

		// lista de idiomas y niveles
		Collection<Language> allLanguages = new ArrayList<Language>();
		Collection<Level> allLevels = new ArrayList<Level>();

		Request request = actionData.getRequest();
		Long personId = null;
		if (request.getParameter("personId")!=null) {
			   personId = new Long(request.getParameter("personId"));
		}
		
		// Seteo el id de persona al formulario.
	    Person person = new Person();
	    if (personId != null)  {
			person = CoreServiceLocator.getPersonService().findPersonById(personId);
			if (person!=null) {
				// Recupero todos las carreras para listarlas en la pagina.
				this.getForm().setUserId(person.getUser().getId().toString());
			}
	    }
		
		return VectricsStrutsAction.FORWARD_SUCCESS;
	}

}
